#include <stdio.h>
#include <math.h>
#include <string>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>

// #include <opencv2/opencv.hpp>
// #include <opencv2/core/core.hpp>
// #include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
// #include <opencv2/core/utils/logger.hpp>

#include "alg.hpp"

extern "C"
{
    #include "correct.h"
}

int main()
{
    cv::Mat src = cv::imread("1.png", cv::IMREAD_COLOR);
    if (src.empty())
    {
        std::cout << "Failed to read image" << std::endl;
        return EXIT_FAILURE;
    }

    cv::Mat gray, img;
    cv::cvtColor(src, gray, cv::COLOR_BGR2GRAY);
    img = gray.clone();

    double x, y;
    correctXY(234, 123, &x, &y);

    // int cx, cy;

    // int height = gray.rows;
    // int width = gray.cols;
    // Image image = {gray.data, height, width};

    // threshold(image, {img.data, height, width}, {0, height, 0, width}, 110, 1);

    // for (int y = 60; y < height - 60;)
    // {
    //     for (int x = 0; x < width - 60;)
    //     {
    //         calCentroid({img.data, height, width}, {y, y+60, x, x + 60}, &cx, &cy);
    //         printf("%d %d\r\n", cx, cy);
    //         drawCross(image, cx, cy, 4);
    //         x = cx + 30;
    //     }
    //     y = cy + 30;
    // }

    cv::threshold(gray, gray, 40, 255, cv::THRESH_BINARY_INV);

    cv::imshow("src", src);
    cv::imshow("gray", gray);
    cv::waitKey(0);

    return EXIT_SUCCESS;
}